#define _MAIN_C

#include "globals.h"
#include "alleg.h"
#include "map.h"
#include "editor.h"
void init_globals(void){
 quit=0;i=0;j=0;  
 sx1=0;sy1=0;sx2=16;sy2=16;
 tx=0;ty=0;tpic=0;
 tdraw1=0;tdraw2=1;tdraw3=2;tdraw4=3;tdraw5=4;
 world_x=0;world_y=0;  
 strcpy(cur_map_name,"NONE"); 
 
 map_x=0;map_y=0;
 cam_x=0;cam_y=0;
 cam_xoff=40;cam_yoff=25;
}    
//Our Main thread.....now for some choppin!
int main (void){
    set_color_depth(16);    
    init_all(SCREEN_SIZE_W,SCREEN_SIZE_H); 
    init_globals();  
    maptiles = (DATAFILE *)load_datafile("data/map.dat");
    buffer = create_bitmap(MAP_W*TILE_SIZE,MAP_H*TILE_SIZE);
    menu_buffer = create_bitmap(640,80);
    init_map();
    for(i=0;i<119;i++){
        keyhold[i]=0;
    }
    while(!quit){ 
     draw_map(map_x,map_y);
     draw_tile_selector();
     draw_buffer(buffer,map_x,map_y,0,0,EDIT_MAP_SIZE_W,EDIT_MAP_SIZE_H);
     draw_menu(); 
     draw_buffer(menu_buffer,0,0,0,EDIT_MAP_SIZE_H,EDIT_MENU_SIZE_W,EDIT_MENU_SIZE_H);
     check_input();    
     do_logic();     
     clear_bitmap(buffer);
     clear_bitmap(menu_buffer);
     rest(25);
    }    
    destroy_bitmap( buffer );
    destroy_bitmap( menu_buffer);
    destroy_tiles();
    unload_datafile( maptiles );
    return 1;
}
END_OF_MAIN();    
